﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Abp.Application.Services.Dto;
using Abp.Runtime.Validation;
using pandx.Mulan.Dto;

namespace pandx.Mulan.Authorization.Users.Dto
{
    public class ObtainUsersInput : PagedSortedAndFilteredInput, IShouldNormalize
    {
        public List<string> Permissions { get; set; }
        public int? Role { get; set; }
        public List<Gender> Gender { get; set; }
        public List<bool> IsActive { get; set; }
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }
        public bool? OnlyLockedUsers { get; set; }

        public bool? SameUnit { get; set; }
        public List<int> RestrictRoles { get; set; }
        public long? Creator { get; set; }

        public void Normalize()
        {
            if (string.IsNullOrEmpty(Sorting))
            {
                Sorting = "User.CreationTime DESC";
            }
            else if (Sorting.Contains("UserName", StringComparison.OrdinalIgnoreCase))
            {
                Sorting = Sorting.Replace("UserName", "User.UserName", StringComparison.OrdinalIgnoreCase);
            }
            else if (Sorting.Contains("Name", StringComparison.OrdinalIgnoreCase))
            {
                Sorting = Sorting.Replace("Name", "User.Name", StringComparison.OrdinalIgnoreCase);
            }
            else if (Sorting.Contains("CreationTime", StringComparison.OrdinalIgnoreCase))
            {
                Sorting = Sorting.Replace("CreationTime", "User.CreationTime", StringComparison.OrdinalIgnoreCase);
            }

            Filter = Filter?.Trim();
        }
    }
}
